package com.ruoyi.integration.service.impl;

import com.ruoyi.integration.config.DustServiceProperties;
import com.ruoyi.integration.response.DustResponse;
import com.ruoyi.integration.service.BaseIoTDataService;
import com.ruoyi.integration.service.token.TokenManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;

import java.util.HashMap;
import java.util.concurrent.ExecutionException;

@Service
public class DustMonitorDataServiceImpl extends BaseIoTDataService {

    @Autowired
    private DustServiceProperties dustServiceProperties;

    private final static Logger logger = LoggerFactory.getLogger(DustMonitorDataServiceImpl.class);

    public DustMonitorDataServiceImpl(WebClient webClient, TokenManager tokenManager) {
        super(webClient, tokenManager);
    }

    public DustResponse fetchData() throws ExecutionException {

        String url = dustServiceProperties.getEndpoint().getDataUrl();
        logger.info("dust-monitor-data-service: {}", url);
        logger.info("dust-monitor-data-service-token: {}", getAccessToken("dust-monitor"));
        HashMap<String, String> headers = new HashMap<>();
        headers.put("Authorization", getAccessToken("dust-monitor"));

        return doGet(url, DustResponse.class, headers);

    }
}
